package com.qf.openapi.web.master.utils;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;

public class MyExResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ex.printStackTrace();//打印异常栈
        //创建一个ModelAndView
        ModelAndView mv = new ModelAndView();
        //识别异常
        if (ex instanceof SQLException) {
            mv.setViewName("redirect:/error/error1.jsp");
        }else if(ex instanceof NullPointerException){
            mv.setViewName("redirect:/error/error2.jsp");
        }else{
            mv.setViewName("redirect:/error/error.jsp");
        }
        return mv;
    }
}
